home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Shareware in MacFormat / LogicSim 2.1 ƒ / LogicSim SDK / LSInterface.p next >
Encoding:
Text File  |  1995-03-15  |  6.2 KB  |  348 lines  |  [TEXT/MWPS]

  1. unit LSInterface;
  2.  
  3.  
  4. interface
  5.  
  6.  
  7.  
  8. {$IFC UNDEFINED THINK_Pascal}
  9.     uses
  10.         Types, QuickDraw, OSUtils, Fonts, Files, Resources;
  11. {$ENDC}
  12.  
  13.     const
  14.         kLeft = 1;
  15.         kRight = 2;
  16.         kTop = 3;
  17.         kBottom = 4;
  18.  
  19.     const
  20.         kExtInput = 1;                 {prmNewClass^.ext = ...}
  21.         kExtOutput = 2;
  22.  
  23.  
  24.     const
  25.         kInputPin = 1;
  26.         kOutputPin = 2;
  27.  
  28.     type
  29.         ClassIDType = record
  30.                 name: Str63;
  31.             end;
  32.  
  33.     type
  34.         XBool = integer;
  35.  
  36.     const
  37.         L0 = 0;
  38.         L1 = 1;
  39.         LX = -1; {unknown}
  40.         LZ = -2; {hight impedance}
  41.  
  42.  
  43. {class messages}
  44.  
  45.     const
  46.         msgNewClass = 1;
  47.         msgDisposeClass = 2;
  48.  
  49.     type
  50.         PrmClassRec = record
  51.                 image: PicHandle;
  52.                 name: Str255;
  53.                 id: ClassIDType;
  54.  
  55.                 fileSpec: FSSpec;     {reserved}
  56.                 ext: integer;        {reserved}
  57.             end;
  58.         PrmClassPtr = ^PrmClassRec;
  59.  
  60. {visual item messages}
  61.  
  62.     const
  63.         msgNewItem = 10;
  64.         msgDisposeItem = 11;
  65.  
  66.         msgSimClick = 12;
  67.         msgDraw = 13;
  68.         msgOptionDialog = 14;
  69.         msgCanOptionDialog = 15;
  70.         msgSetItemParams = 16;
  71.         msgGetItemParams = 17;
  72.  
  73.     type
  74.         PrmItemRec = record
  75.                 frame: Rect;
  76.                 modifiers: integer;
  77.                 canOptionDialog: Boolean;
  78.                 paramsStorage: Handle;
  79.             end;
  80.         PrmItemPtr = ^PrmItemRec;
  81.  
  82. {gate messages}
  83.  
  84.     const
  85.         msgNewGate = 20;
  86.         msgDisposeGate = 21;
  87.  
  88.         msgReset = 22;
  89.         msgSimulation = 23;
  90.         msgGetGateParams = 26;
  91.  
  92.  
  93.     type
  94.         PrmGateRec = record
  95.                 paramsStorage: Handle;
  96.             end;
  97.         PrmGatePtr = ^PrmGateRec;
  98.  
  99.     type
  100.         LSEnvRec = record
  101.                 setOutputProc: ProcPtr;
  102.                 getInputProc: ProcPtr;
  103.                 addTimerProc: ProcPtr;
  104.                 declarePinProc: ProcPtr;
  105.                 forceGateSimProc: ProcPtr;
  106.                 invalItemProc: ProcPtr;
  107.                 loopProc: ProcPtr;
  108.                 addTimer: ProcPtr;
  109.                 {and other datas ...}
  110.             end;
  111.         LSEnvPtr = ^LSEnvRec;
  112.  
  113.  
  114.         ClassRefT = ^char;
  115.         ItemRefT = ^integer;
  116.         GateRefT = ^longint;
  117.  
  118.         LSParamPtr = record
  119.                 case integer of
  120.                     0: (
  121.                             prmClass: PrmClassPtr;
  122.                     );
  123.                     1: (
  124.                             prmItem: PrmItemPtr;
  125.                     );
  126.                     2: (
  127.                             prmGate: PrmGatePtr;
  128.                     );
  129.             end;
  130.  
  131.         LSBlock = record
  132.                 varCode: longint;
  133.                 msg: longint;
  134.                 prm: LSParamPtr;
  135.                 classRef: ClassRefT;
  136.                 itemRef: ItemRefT;
  137.                 gateRef: GateRefT;
  138.                 classDatas: Handle;
  139.                 itemDatas: Handle;
  140.                 gateDatas: Handle;
  141.                 env: LSEnvPtr;
  142.                 reserved: longint;
  143.             end;
  144.  
  145.     procedure CallComponentDefProc (blk: LSBlock;
  146.                                     proc: ProcPtr);
  147.     inline
  148.         $205F, $4E90;
  149.  
  150.  
  151.     procedure LSDeclarePin (env: LSEnvPtr;
  152.                                     classRef: ClassRefT;
  153.                                     loc: point;
  154.                                     kind: integer;
  155.                                     name: Str63);
  156.     procedure LSGetInput (env: LSEnvPtr;
  157.                                     gateRef: GateRefT;
  158.                                     pin: integer;
  159.                                     var value: XBool);
  160.     procedure LSSetOutput (env: LSEnvPtr;
  161.                                     gateRef: GateRefT;
  162.                                     pin: integer;
  163.                                     value: XBool);
  164.     procedure LSForceGateSim (env: LSEnvPtr;
  165.                                     gateRef: GateRefT);
  166.     procedure LSInvalItem (env: LSEnvPtr;
  167.                                     itemRef: ItemRefT);
  168.     procedure LSAddTimer (env: LSEnvPtr;
  169.                                     gateRef: GateRefT;
  170.                                     date: longint);
  171.     procedure LSLoop (env: LSEnvPtr;
  172.                                     itemRef: ItemRefT);
  173.  
  174.     function Pnt (h, v: integer): Point;
  175.  
  176.     function CompareClassID (id1, id2: ClassIDType): boolean;
  177.     procedure SetClassID (var id: ClassIDType;
  178.                                     s: str63);
  179.  
  180.     function _AND (a, b: XBool): XBool;
  181.     function _OR (a, b: XBool): XBool;
  182.     function _NOT (a: XBool): XBool;
  183.     function RisingFront (oldv, newv: XBool): boolean;
  184.  
  185.  
  186. implementation
  187.  
  188.     function CompareClassID (id1, id2: ClassIDType): boolean;
  189.     begin
  190.         CompareClassID := (id1.name = id2.name);
  191.     end;
  192.  
  193.     procedure SetClassID (var id: ClassIDType;
  194.                                     s: str63);
  195.     begin
  196.         id.name := s;
  197.     end;
  198.  
  199.     function Pnt (h, v: integer): Point;
  200.         var
  201.             p: Point;
  202.     begin
  203.         p.h := h;
  204.         p.v := v;
  205.         Pnt := p;
  206.     end;
  207.  
  208.     function _AND (a, b: XBool): XBool;
  209.         var
  210.             result: XBool;
  211.     begin
  212.         if (a = L1) & (b = L1) then
  213.             result := L1
  214.         else if (a = L0) | (b = L0) then
  215.             result := L0
  216.         else
  217.             result := LX;
  218.         _AND := result;
  219.     end;
  220.  
  221.     function _OR (a, b: XBool): XBool;
  222.         var
  223.             result: XBool;
  224.     begin
  225.         if (a = L1) | (b = L1) then
  226.             result := L1
  227.         else if (a = L0) & (b = L0) then
  228.             result := L0
  229.         else
  230.             result := LX;
  231.         _OR := result;
  232.     end;
  233.  
  234.     function _NOT (a: XBool): XBool;
  235.         var
  236.             result: XBool;
  237.     begin
  238.         if a = L0 then
  239.             result := L1
  240.         else if a = L1 then
  241.             result := L0
  242.         else
  243.             result := LX;
  244.         _NOT := result;
  245.     end;
  246.  
  247.     function RisingFront (oldv, newv: XBool): boolean;
  248.     begin
  249.         RisingFront := ((newv = L1) & (oldv = L0));
  250.     end;
  251.  
  252.     procedure Call_DeclarePin (classRef: ClassRefT;
  253.                                     loc: point;
  254.                                     kind: integer;
  255.                                     name: Str63;
  256.                                     proc: ProcPtr);
  257.     inline
  258.         $205F, $4E90;
  259.  
  260.     procedure LSDeclarePin (env: LSEnvPtr;
  261.                                     classRef: ClassRefT;
  262.                                     loc: point;
  263.                                     kind: integer;
  264.                                     name: Str63);
  265.     begin
  266.         Call_DeclarePin(classRef, loc, kind, name, env^.declarePinProc);
  267.     end;
  268.  
  269.     procedure Call_SetOutput (gateRef: GateRefT;
  270.                                     pin: integer;
  271.                                     value: XBool;
  272.                                     proc: ProcPtr);
  273.     inline
  274.         $205F, $4E90;
  275.  
  276.     procedure LSSetOutput (env: LSEnvPtr;
  277.                                     gateRef: GateRefT;
  278.                                     pin: integer;
  279.                                     value: XBool);
  280.     begin
  281.         Call_SetOutput(gateRef, pin, value, env^.setOutputProc);
  282.     end;
  283.  
  284.     procedure Call_GetInput (gateRef: GateRefT;
  285.                                     pin: integer;
  286.                                     var value: XBool;
  287.                                     proc: ProcPtr);
  288.     inline
  289.         $205F, $4E90;
  290.  
  291.     procedure LSGetInput (env: LSEnvPtr;
  292.                                     gateRef: GateRefT;
  293.                                     pin: integer;
  294.                                     var value: XBool);
  295.     begin
  296.         Call_GetInput(gateRef, pin, value, env^.getInputProc);
  297.     end;
  298.  
  299.  
  300.     procedure Call_ForceGateSim (gateRef: GateRefT;
  301.                                     proc: ProcPtr);
  302.     inline
  303.         $205F, $4E90;
  304.  
  305.     procedure LSForceGateSim (env: LSEnvPtr;
  306.                                     gateRef: GateRefT);
  307.     begin
  308.         Call_ForceGateSim(gateRef, env^.ForceGateSimProc);
  309.     end;
  310.  
  311.  
  312.     procedure Call_InvalItem (itemRef: ItemRefT;
  313.                                     proc: ProcPtr);
  314.     inline
  315.         $205F, $4E90;
  316.  
  317.     procedure LSInvalItem (env: LSEnvPtr;
  318.                                     itemRef: ItemRefT);
  319.     begin
  320.         Call_InvalItem(itemRef, env^.InvalItemProc);
  321.     end;
  322.  
  323.     procedure Call_Loop (itemRef: ItemRefT;
  324.                                     proc: ProcPtr);
  325.     inline
  326.         $205F, $4E90;
  327.  
  328.     procedure LSLoop (env: LSEnvPtr;
  329.                                     itemRef: ItemRefT);
  330.     begin
  331.         Call_Loop(itemRef, env^.loopProc);
  332.     end;
  333.  
  334.  
  335.     procedure Call_AddTimer (gateRef: GateRefT;
  336.                                     date: longint;
  337.                                     proc: ProcPtr);
  338.     inline
  339.         $205F, $4E90;
  340.  
  341.     procedure LSAddTimer (env: LSEnvPtr;
  342.                                     gateRef: GateRefT;
  343.                                     date: longint);
  344.     begin
  345.         Call_AddTimer(gateRef, date, env^.addTimerProc);
  346.     end;
  347.  
  348. end.